package huoye.shops.huoye.operation.presenter;

import android.util.Log;

import com.codeideology.android.lang.entity.Paging;

import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.common.model.OssImageData;
import huoye.shops.huoye.operation.activity.VipGuestsActivity;
import huoye.shops.huoye.operation.model.GuestsDetailData;
import huoye.shops.huoye.operation.model.VipGustsData;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IGuestsSetView;
import huoye.shops.huoye.operation.view.IVipGuestsRefreshView;


/**
 * Created by uesr on 2017/7/19.
 */

public class GuestsSetPresenter extends BasePresenter<IGuestsSetView> {

    OperationService mService;


    //获取特权用户详情
    public void getPrivilegedGuestDetail(final String shopSpeGuestId){
        //view.showProcessingIndicator();
        mService.getPrivilegedGuestDetail(shopSpeGuestId ,new MineBaseJsonRequestCallback<GuestsDetailData>(GuestsDetailData.class) {

            @Override
            public void onSuccess(GuestsDetailData guestsDetailData) {
                super.onSuccess(guestsDetailData);
                view.getDetail(guestsDetailData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //修改用户特权次数
    public void modifyPrivilegedGuest(String shopSpeGuestId,String prlNum){
        // view.showProcessingIndicator();
        mService.modifyPrivilegedGuest(shopSpeGuestId ,prlNum,new MineBaseJsonRequestCallback<GuestsDetailData>(GuestsDetailData.class) {

            @Override
            public void onSuccess() {
                super.onSuccess();
                view.makeToast("用户特权次数修改成功");
                view.finish();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //添加特权用户
    public void addPrivilegedGuest(String requestUserId,String userId,String prlContent,String imgUrls,String prlNum,String endTime){
                Log.e("test",endTime);
        if(prlContent.equals("")){
            view.makeToast("请输入特权内容");
            return;
        }else if(imgUrls.equals("")){
            view.makeToast("请选择嘉宾图片");
            return;
        }else if(endTime.equals("选择到期时间")){
            view.makeToast("请选择特权到期时间");
            return;
        }else{
            mService.addPrivilegedGuest(requestUserId,userId,prlContent,imgUrls ,prlNum,endTime,new MineBaseJsonRequestCallback<GuestsDetailData>(GuestsDetailData.class) {
                @Override
                public void onSuccess() {
                    super.onSuccess();
                    view.makeToast("添加特权用户成功");
                    view.startActivity(VipGuestsActivity.class);
                    view.finish();
                }

                //网络请求失败
                @Override
                public void onFailure(String msg, String code, Throwable e) {
                    super.onFailure(msg, code, e);
                    view.makeToast(msg);
                }

                //加载结束
                @Override
                public void onNetworkFail() {
                    super.onNetworkFail();
                    view.onNetworkFail();
                }

                //加载中
                @Override
                public void onFinish() {
                    super.onFinish();
                    view.hideProcessingIndicator();
                }
            });
        }

    }




    //图片上传
    public void uploadOssImg(String id,String type,String filePath){
        //  view.showProcessingIndicator();
        mService.uploadOssImg(id,type,filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess(List<OssImageData> list) {
                super.onSuccess(list);
                Log.e("test",list.get(0).toString());
                OssImageData ossImageData = list.get(0);
                view.setUpload(ossImageData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }


    //图片删除
    public void deleteOssImg(String filePath){
        //  view.showProcessingIndicator();
        mService.deleteOssImg(filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess() {
                super.onSuccess();
                view.makeToast("OSS图片删除成功！");
                view.setDelete();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }




    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
